home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group01b.txt / 000065_icon-group-sender_Thu Apr 26 08:27:30 2001.msg < prev    next >
Internet Message Format  |  2002-01-03  |  6KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id f3QFOqU08842
  4.     for icon-group-addresses; Thu, 26 Apr 2001 08:24:52 -0700 (MST)
  5. Message-Id: <200104261524.f3QFOqU08842@baskerville.CS.Arizona.EDU>
  6. Date: Wed, 25 Apr 2001 18:55:31 -0500
  7. From: gep2@terabites.com
  8. Subject: [ICON]Answer.... for someone else ;)
  9. To: icon-group@cs.arizona.edu
  10. Cc: Rafal.Sulejman@extern.oppenheim.de
  11. Errors-To: icon-group-errors@cs.arizona.edu
  12. Status: RO
  13. Content-Length: 5152
  14.  
  15. Passing along by request this interesting reply to the "rotating numbers" 
  16. thread....
  17.  
  18. <---- Begin Forwarded Message ---->
  19. From: Rafal.Sulejman@extern.oppenheim.de
  20. To: gep2@terabites.com
  21. Subject: [ICON]Answer.... for someone else ;)
  22. Date: Wed, 25 Apr 2001 21:21:24 +0200
  23.  
  24. Hi,
  25. Greetings from Koeln/Germany. ;)
  26.  
  27. It's for someone from icon-group@...
  28. AFAIK you're subscribed, too.
  29. Because I cannot [it's only beginning of my CANNOTS list ;(((  ] subscribe
  30. (read:answer) using this address -- pls. fwd :)
  31.  
  32. Few weeks ago on the icon-group someone wrote:
  33. > > >> 142857 is a cyclic number, the numbers of which always appear in the
  34. > > >> same order but rotated around when multipled by any number from 1 to
  35. 6.
  36. > > >>
  37. > > >> 142857 * 2 = 285714
  38. > > >> 142857 * 3 = 428571
  39. > > >> 142857 * 4 = 571428
  40. > > >> 142857 * 5 = 714285
  41. > > >> 142857 * 6 = 857142
  42. > > >>
  43. > > >> So can you find any more numbers like this? Is there a simple
  44. algorithm
  45. > > >> for finding them or is this another good application for parallel
  46. > > >> machines?
  47. > >
  48.  
  49. I forwarded this message to _other_ group (over 100 msg in thread!!!!!).
  50. One of the most relevant answers is:
  51.  
  52. > > The reason this number has such magical properties is because it is the
  53. > > number (1/7) * 100_000.  The fraction 1/7 has a repeating series of
  54. digits
  55. > > "142857".  And, when you multiply this fraction by 2, 3, 4, ..., the
  56. > > digits appear in a shuffled order; thus, 142857 is just an employment of
  57. > > 1/7's magic.
  58. >
  59. > But this does not explain _why_ it happens.
  60. > E.g. why does it work with 1/7 and not with 1/3, 1/11, 1/13... ?
  61. >
  62. > To make the question more general:
  63. > Find all integers a, n with 1 < a < n such that the digits of the
  64. > fraction a/n are a rotation of the digits of the fraction 1/n.
  65. >
  66. > Examples:
  67. > (a,n) = (2,7), (3,7), ... , (6,7); (10,11); (3,13), (4,13), (9,13), ...
  68. >
  69. > I don't know how difficult is this question.
  70. > When you've solved it in base 10 you can try it in arbitrary base D.
  71.  
  72. Sure!
  73.  
  74. First I had to narrow down the problem a bit to make it manageable. Now that
  75. I
  76. know more, I suppose I could give it a wider shot, but I'm tired and
  77. underequipped, anyways.
  78.  
  79. Task: find number-pairs D,n where for n applies:
  80.  
  81. for every m in [1,n[, the period in numeric representation of m/n in base D
  82. is
  83. the period of 1/n with sufficient rotating shift.
  84.  
  85. For example:
  86.  
  87. 1/7 = 0.142857...
  88. 2/7 = 0.  285714...
  89. 3/7 = 0. 428571...
  90.  
  91. And so on. So, obviously, one such (D,n) is (10,7). And now on the findings:
  92.  
  93. Any 1/n whose numeric representation's period is n-1 digits in length is
  94. rotating. I also know that if there's no trailing sequence, that is, the
  95. period
  96. starts right after decimal (D'mal) point, then the complete rotation (all
  97. m/n)
  98. is only possible if the period is n-1 digits.
  99.  
  100. And you can find rotating (D,n):s like this:
  101.  
  102. For some (D,n), find smallest p for which it is true that:
  103.  
  104. (D^p-1) % n = 0
  105.  
  106. [% is integer modulo, like in C]
  107.  
  108. In other words, that (D^p-1) is divisible with n. Now, if
  109. p=n-1
  110. then (D,n) is the rotating pair that we were looking for.
  111.  
  112. That much I could prove so far. On the hunches department: All n, regardless
  113. of
  114. D, that I could find, are primes.
  115.  
  116. If it's true that (D^(n-1)-1) % n = 0 but n-1 is not the smallest power that
  117. executes that, then it's not completely rotating but it seems it /might/ be
  118. still rotating for some parts.
  119.  
  120. Other way to find these numbers, likely more CPU-intensive (isn't there a
  121. builtin modulo instruction in x86 cpus or something?) but can handle much
  122. larger numbers:
  123.  
  124. f(0)=1
  125. f(x)=(D*f(x-1)) % n
  126.  
  127. If the first value of f after x=0 is at n-1, then (D,n) is rotating.
  128.  
  129. --
  130.  
  131. If my ranting is too confusing, I've attached a code to find for such pairs.
  132. Thank you for your disinterest, if someone would care for a proof, ask. It's
  133. amateurish and I've forgotten half of it, I'll probably forget the other
  134. half
  135. by tomorrow.
  136.  
  137.  -Kaatunut
  138.  
  139. /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
  140. #include <stdio.h>
  141. #include <stdlib.h>
  142.  
  143. int main(int argc,char* argv[]) {
  144.     char buff[400];
  145.     int Dm,DM,nm,nM;
  146.     int D,n;
  147.     
  148.     printf("D search range start? ");
  149.     fgets(buff,400,stdin);
  150.     Dm=strtol(buff,NULL,0);
  151.     printf("D end (-1 for endless)? ");
  152.     fgets(buff,400,stdin);
  153.     DM=strtol(buff,NULL,0);
  154.     
  155.     printf("n start? ");
  156.     fgets(buff,400,stdin);
  157.     nm=strtol(buff,NULL,0);
  158.     printf("n end (-1 for endless)? ");
  159.     fgets(buff,400,stdin);
  160.     nM=strtol(buff,NULL,0);
  161.     
  162.     for (D=Dm;DM==-1 || D<=DM;++D)
  163.         for (n=nm;nM==-1 || n<nM;++n) {
  164.             int q=1,p;
  165.             for (p=1;p<=n && (q!=1 || p==1);++p)
  166.                 q=(D*q)%n;
  167.             if (p==n)
  168.                 printf("(%d,%d)\n",D,n);
  169.         }
  170. }
  171. /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
  172.  
  173. It's (as you see) in C, but it won't be hard to rewrite this in any
  174. (s4,icon,vb) programming language...
  175. Hope it's worth reading...
  176.  
  177.  
  178. Rgds,
  179.  
  180. --Rafal Sulejman <rafal.sulejman@extern.oppenheim.de>
  181.  
  182.  
  183. <----  End Forwarded Message  ---->
  184.  
  185. Gordon Peterson                  http://personal.terabites.com/
  186. Support the Anti-SPAM Amendment!  Join at http://www.cauce.org/
  187. 12/19/98: Partisan Republicans scornfully ignore the voters they "represent".
  188. 12/09/00: the date the Republican Party took down democracy in America.
  189.  
  190.  
  191.